package com.cpd.blog.task;

import com.cpd.blog.common.constant.Properties;
import com.cpd.blog.manager.manager.ArticleManager;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import net.javacrumbs.shedlock.spring.annotation.SchedulerLock;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * @Author: Copydown
 * @Date: 2022/05/06/14:26
 */
@Slf4j
@Component
@RequiredArgsConstructor
@ConditionalOnProperty(value = Properties.ENABLE_MYSQL_TASK, havingValue = "true")
public class RefreshMySqlTask {

    private final ArticleManager articleManager;

    @Async("myThreadPool")
    @Scheduled(cron = "${schedule.refresh-mysql.cron}")
    @SchedulerLock(name = "refreshNewArticleLock",
            lockAtLeastFor = "${schedule.refresh-mysql.minLockTime}",
            lockAtMostFor = "${schedule.refresh-mysql.maxLockTime}")
    public void refreshNewArticle() {

        log.info("{}", articleManager.refreshNewArticle());
    }

}
